I work in the engineering dept. of a Class 1 railroad (that will remain nameless for job security reasons.)
"modern, high density steel" has nothing to do with it. Indeed, I have seen 100 year old rail welded together for use on branch lines and in yards.
The third posting is correct in saying that rail will expand in all three dimensions, up/down, sideways, and longitudinally. However, rail will generally try to expand lengthwise first, then sideways, and only up or down in extreme cases (remember, the cross section of rail is designed to be easily bent sideways but be resistant to bending vertically, otherwise it would just give way under the weight of a train.) The ballast restrains the sideways movement by being packed around and under the ties, and from the indentations the points of the ballast make in the bottom of the tie (the latter is about 60 to 70 percent of the holding power restraining the track).
The rail is restrained from longitudinal movement by using rail anchors, usually clipped on either side of the tie on every other tie "boxed" as we say in the trade. (Pandrol or other type "clips" restrain the rail by pressing it down into the tie plate, and are used on concrete ties where regular anchors won't work). The secret is to heat the rail before it is anchored, so it remains in tension under all circumstances. There is some leeway in the temperature, but ideally it should be heated to around 100 deg. F before anchoring. This means that on hot days the rail will be in stasis, tension wise, and will exert an increasing pull as it contracts as it gets colder. It is much easier to deal with the consequences of the rail pulling apart, since a pulled joint or broken rail will activate the signal system. If you don't heat the rail enough, or if you add rail in cold weather and don't adjust it come Spring, the track will buckle, or kick to the side (some call this a "sun kink"). Buckled track does not break the signal circuit, and thus is far more dangerous because a train will encounter it at full track speed instead of restricted speed after passing a stop signal.
If you have any other questions of a more technical nature, please contact me off list.