Is is necessary to book my train ticket from London to York in advance or can I just do it at the station?
You can do it at the station. York is on a common, heavily traveled route.
I ordered my train ticket for the same route in advance and it was much cheaper as stated above. I would just add that it was super easy to get the ticket from the machine at the station, using the confirmation code you're given when you order.
Yes, you can do it at the station; but except for commuter trains, walk-up fares in the UK are horrendously expensive. For London-York the 2nd class fare is £92.50. If you book 30-60 days in advance at www.gner.co.uk, you can get a fare as low as £10.00. Note, however, that the ticket will only be good for a specific date and time. You have to register on the GNER site before booking. If you're asked for a UK postal code, use one from any London hotel. Then when it comes time to pay, change your address to match the one on the credit card you're using.
prebook , for much cheaper fares. If yuo are travelling soon, check the GNER site, a £5 offer was issued yesterday.