Push Pull setup for LED

Do you have a pulldown on the phototransistor to pin connection?

The transistor lets current into that wire when light is on it, fills the wire up and if there's no slow drain the wire stays charged even after the transistor is off, and your pin reads that.

Same pin as the sensor, run a wire with a 10k resistor to GND and only when the phototransistor is ON will the pin read HIGH.

No schematic here or above, it's hard to tell what you have.