Suppress noise on digital signal
Because both sides of the opto share a common GND, it is not addressing one of the most common noise sources.  However, it does add something to the circuit.  Basically, it is functioning as a comparator without hysteresis.  And, significantly, without debounce.  You can debounce the switch signal in software, but you have not stated that this is being done.  As shown, you will have to flip the logic polarity in software because the opto is configured as an inverter.
Suggestion:  Move R1 to the +5 V side of the switch, and connect the U1 anode directly to the switch output.  This limits the short circuit current if there is a wiring fault from either side of the cable to the frame.
Suggestion:  Configure the opto output as an emitter follower.  This preserves the input logic polarity, and the output now is equivalent to the original circuit.  Also, you can add a resistor from U1 pin 7 to pin 1 for some hysteresis.