If no energy is lost to heat, it remains constant is potential energy stored in the spring is exchanged with kinetic energy of mass in motion during each cycle.
This is what thermal energy "looks" like: Random motion and random compression of atoms behaving almost as springs.
More heat flows out of something hot than flows into something cold. The difference in energy (called W) can be used to drive a mechanical motor. That might explain why motors and people overheat when they work too hard.