Even though I recommend staying overnight in Matera (so you can get the full experience + sleep in cave hotel), this city is also a popular destination for a day trip from Bari. If you're short on time, you can always visit Matera for just a few hours and still see a lot that the city has to offer.