As a rule there is no one best material for anything, although for jigs it's almost universal that plywood or MDF are recommended these days for the major elements, but they are not the only options. Also note that not all ply or MDF is created equal, and the storage conditions where they were bought is a factor too (whether stored dead flat being the main one).
Overall I would prefer to use plywood for something like this myself for a couple of reasons, primarily because a mid-range ply is stronger and more resilient than MDF. But that said, many many jigs for table saws have been successfully made from MDF and given reliable service for years after.
on final screw up it lost its accuracy
I wonder if you weren't using clamps here (or enough of them) to hold the fence firmly in position while the screws were being driver. An additional aid worth considering is a couple of square clamping guides of one kind or another, e.g. something like this:
I was only using a 18 mm MDF strip for the fence.
That would usually be plenty thick enough. The overall size of the piece could have been a factor, and/or the quality of the MDF.
If in doubt laminate it with something to stiffen it up (doesn't have to be another piece of the 18mm MDF, but you can't go too stiff here and the added bulk of another 18mm of thickness on the fence wouldn't normally be a hindrance during use).
From your Comment underneath the main Question:
I wondered about gluing it. I just wondered if I would be quick enough to adjust it before it set
A tip to help with this is to drill clearance and pilot holes for your positioning screws for the fence, with the fence firmly clamped in place and checked for accuracy, then drive all screws home, check for square and then withdraw the screws.
This will allow for a very quick (and hopefully still very accurate) fixing of the fence once glue has been applied, with little if any problem of it moving out of alignment due to the lubrication provided by the glue.
In case it helps, a previous Answer has some details on how you might construct one of these, requiring minimal work on keeping things square.