Trucks are used for shipments to more local warehouses or retail/factory locations that don't have rail access. And no, it's not feasible to build a rail spur to every warehouse or Wal-mart.
Low-speed (15 - 30 mph) tracked autonomous vehicles for local ("last 10 - 20 mile") delivery might very much make sense.
It's a lot easier to focus on things like traffic control and hazard detection (including people on tracks) when your wheels literally hold you to the road.
The major rail companies would much rather move mile long trains hundreds of miles on well maintained track, and let the short lines fend for themselves, barely scraping by, running trains at a few miles an hour (as they can't afford proper track maintenance.
While $5B is still a lot of money, it's smaller than the $8B that funds mass transit.
The difference isn't enough to compensate for the increased wear but there is a difference.
What are working conditions of truckers relative to railroad workers?