For the Prusa line of printers, there is a device known as the MMU in versions 2 and 3 to the best of my understanding. It operates by pulling in the desired color/material to the extruder/hot-end and then retracting it to provide for a color/material change. Operators of this device experience problems similar to yours.
There are third-party creators who have designed models known as buffers. Using the search terms "mmu buffer" results in a number of options, most of which are overkill for your concerns.
Thingiverse search does present what is described as Prusa MMU Mini Buffer MK2 and shows a single filament device providing for "take-up" of the retracted filament.
Image from linked site.
Printables has a similar collection, most of which are also overkill, in my opinion.
I have experienced similar problems, especially with a new, full spool. I have also seen attachments to the axle of the spool holder that places a bar across the flanges of the spool, but am currently unable to locate such a model. My print attempt failed due to modifications I've made to the axle and the model has been binned.
Additionally, I redirected the filament vertically downward on the back of the (enclosed) printer, through a loop of PTFE tubing and upward again to the filament entry point. When the retraction action took place, the filament was pushed rearward but not downward, nor upward, causing no effect on the spool. It's a hack job using cable ties to hold the PTFE tubing to the fan grilles but it works. Unfortunately no photos and it would have to be custom fit to your configuration.
Some of the MMU solutions incorporate a ramped axle holder on which the spool is pulled upward while filament is being extruded, then allowed to roll downward, returning the excess filament to the spool. Depending on your level of irritation, this may not be overkill, as it is a mechanically simple design and appropriately reliable.