Solenoids causing Arduino to malfunction despite protection diode
Those are common symptoms of layout problems, or possibly power supply issues if your 5V supply is derived from your 25V (like through a buck regulator).  You want to make sure the ground paths are separate for your 5V and 25V sides, then meet at exactly one point as close as possible to the supplies.  If that's not sufficient, the next step would be completely isolating the circuits with an optoisolator.