There are a lot of things that can go wrong with the 140,695 miles of railroad covering America. The tracks have to be inspected regularly and, rather than send crews out in full-sized train cars, these modified automobiles often did the job.
Worn tracks have been the second top cause of catastrophic train derailments since the advent of locomotion (just behind human error). They're constantly exposed to thermal stress, environmental corrosion, and the wear from perpetually heavier and faster trains running over them. The track wear often causes the rails to crack or warp, similar to the effect of pulling on each end of an AbbaZabba, hence the need to inspect the railways regularly.
Until the 1990's and the development of non-destructive testing (NDT) methods, track inspections were primarily performed visually. Crews of track walkers were employed to routinely check the track's gauge wear and ensure the switches were operational.
And to get the crews out to inspection sites, railroad companies relied on Speeders — small, motorised train cabs — and, occasionally modified street cars like these, known as Highway-Rail Vehicles or Hi-rails. They were capable of driving both on- and off-track thanks to the inclusion of a set of drop-down flanged wheels. This allows the vehicles to reach sections of track otherwise inaccessible by road but still allows the cars to clear the tracks if a train approaches.
Modern Hi-rails are typically converted trucks rather than posh cruisers from the 30's and 40's, which is a shame, though they are often also equipped with cow-catchers, which is all sorts of awesome.
Side note: you can see an excellent example of this in Die Hard with a Vengeance (the one with Samuel L. Jackson) in the flooding metro tunnel scene.
And if anybody can identify the make and models of these rides, let me know in the comments. [Book of Joe