It is a lot cheaper if you buy tickets in advance. The disadvantage is that tickets are specific to one train. Once you have bought tickets you cannot change your mind and go on a later or earlier train.
The normal advice is to buy early, EXCEPT if you are arriving of an intercontinental flight, as you cannot predict when you will emerge from the airport (Flight late, immigration, . . .). In this case just swallow the higher price and buy on the day. Tickets will be available. They very rarely sell out, and if they do there is another train in 30 or 60 minutes.
For times and buying tickets see the Trenitalia website (the company that runs the trains). Compare prices for later today with those for 2 months away, and see the difference: http://www.trenitalia.com/tcom-en
For lots of background info about Italian trains, see here: https://www.seat61.com/Italy-trains.htm