Using twisted pair with Arduino Mega
I have dealt with noise and spikes on industrial equipment that was problematic even with opto-isolated I/O points. First off, are you running these wires directly from the I/O pins around the machine? If so, this is what needs to be addressed. Tell us what these pins are connected to such as relays, analog points, etc. From there, we can then assist you in figuring out what to do.

Some anecdote:

I was rebuilding an in house laser welding workstation with a new continuous wave laser with opto-isolated I/O. The machine also had a few big solenoids for shield gas and an air knife which blew spatter and smoke/vapors away from the protective cover glass of the laser head. Every time the air solenoid was shut off, the laser beam would pulse. Even though I had a flyback protection diode and emf filtering, that big solenoid coil was a real emf problem. I fixed it by doing two things. First I put the solenoids on their own power supply and electrically isolated the two DC systems. I then physically separated the wiring and moved the solenoid wiring and relays to another location away from the sensitive I/O wiring from the CNC controller. Worked perfectly.

Another story was a stepper motion system was false triggering I/O points from the PWM noise induced on the I/O wires from being in close proximity to the motor wires. Since the motors were in a vacuum chamber with only one common feed through for all wiring, I couldn't shield or isolate the wiring. I put a scope on the line and looked at my noise frequency and sized appropriate filter capacitors. The I/O voltage was 24VDC so I loaded the I/O wiring with 2.7k 1/2 W resistors along with the capacitors. That again solved my noise issues.