If you heat a uniform metal plate with a hole in it, will the hole get larger or smaller?
The answer is: smaller.
This is because the metal will expand in all the directions, so the edge of the hole expand too. If the metal expand the hole becomes smaller.
Every piece of rail isn't perfectly near to the other one (not many millimeters..), because in summer this little hole will disappear for the heat. If this hole is missing, the deformation of the rail makes the train derail.