If you get electrical noise in the cable from the switch it can look to Mach as if there has been a signal, it doesnt matter whether it is opto isolated or not .
5v is very prone to noise as the difference between High and Low is fairly close in voltage terms, that is the reason industrial controls use mostly 24V for their I/0, as the difference between high and low is much greater. I use 24v on my lathe and Beaver mill and then just use relays or opto board to convert to 5v prior to passing to the BOB, this makes it almost impossible for noise to be an issue.
Having shielded cables and having the shielding grounded at one single point in the control cabinet can make 5v work well enough, my Bridgeport has that and debounce is zero, but if I was re-doing the Bridgeport I would have 24v I/O.
Hood