put an oscilloscope/logic analyser on gpio.4 and see what the signal looks like or if you don't have one
put a led on gpio.4 in lieu of whats there now if it does not change state when gpio.5 is read then whatever is on gpio.4 is loading pin excessively.
or else your description of the problem maybe unclear or inaccurate

there are several of these
gosub sub9

i cant see a sub9 anywhere in your code