Any piece of ferrous metal (like iron or steel) that remains in a fixed position on the earth's surface for a significant period of time tends to get magnetized by the earth's magnetic field. This effect isn't just limited to railroad tracks; it happens to just about every piece of ferrous metal on earth. Take a pocket compass and run it up and down along the surface of any long iron bar that has been fixed into position for some time and you'll notice that the needle swings around whenever you pass middle point of the bar's length, which is an indication that the bar has two magnetic poles and is hence, magnetized. Moreover, when you compare all such stationary magnetized metal in your area, you'll find that they are all magnetized the same way.
making a small donation to science.ca.