That's a great idea. You could just put the overhead charging infrastructure at a few stations on the line. Just enough to top the batteries up. Most of the energy could probably be recovered through regenerative braking, but of course some will be lost through mechanical and air resistance.
This would be so much simpler than electrifying the whole line and much easier to maintain.
This infrastructure is often already at key stations, and so it might require no extra work to implement them. Just more money for the battery powered trains.