How best to connect two optical limit switches to share one I/O pin
Yes, it will work.

You need to add a pull-up resistor (from the OUT node to VCC) to be sure the output goes high when none of the limits have been hit. This can be anything from maybe 500 ohms to 10 kohms, with lower values giving faster response when exiting the limit condition and higher values giving lower power consumption when in the limit condition. If you have no other reason to choose, 4.7 kohm is a reasonable choice.