My problem usually occurred when I turned on a fluorescent light.
Now I use a different PC the problem is gone, and the homing switches are more consistent.
This points to a poor quality parallel card in the original computer.
In the original computer I needed to buffer the limit switches to the PC for reliable operation. This problem went away also.
It was a parallel port integrated on the mother board.
The brand name PC used now has a parallel port that electrically meets the standards.
On the original one the inputs were pulling up too hard, hence never pulled low adequately, with standard TTL drive.
This was caused by the configuration of the integrated chip not conforming to TTL conventions. I'm sure some printers would not be very happy with it too.