temperature is fine at idle, but gets hot when driving
Slow coolant flow, causes could be a bad water pump, partially plugged radiator, thermostat not opening fully, electric cooling fan running backwards, sounds weird I know but I have seen it happen.
Most probably catastrophic head gasket failure that's allowing percolation of exhaust into now-superheated coolant. Send this chariot to a bone yard....
Like TheSub said (except getting rid of it - that's up to you). Good read: https://allwheeldriveauto.com/subaru-head-gaskets- problems-explained-part-ii/
Looking for a Used Legacy in your area?
CarGurus has 15,231 nationwide Legacy listings starting at $950.
Search Subaru Legacy Questions
Are you a UK consumer? CarGurus now has a discussion forum in the UK.
Subaru Legacy Experts