Resistor on outgoing signal lines - the logic behind it
A simple explanation is that wires on PCB and in cables have capacitance. Adding a resistor before capacitance makes an RC filter which is a low-pass filter that removes high frequency content.
It means that the IO pin driving the wire does not have a direct capacitive load, as there is a resistor to limit the current to capacitance, so the current peak at the signal edges is smaller, and voltage changes slower.
And the closer the resistor is to the output pin, the less capacitive load there is directly at the output pin, so the placement of the resistor does matter, and will not help the output pin if it is at the receiving end of the wiring. It can still protect the receiving IO pin from the spiky signals.
A more complex explanation involves transmission line theory, which says that any impedance mismatch and  discontinuities in the impedance creates reflections, which is another reason to match the IO pin output impedance with a resistor to the impedance of wires being used to carry the signals.