You've not said what IR sensor you are using. Some are strongly influenced by ambient IR light, be that clouds moving and soaking your machine in sunlight or turning on and off a halohen/filament desk light.

Edit: Just seen M665 relates to delta machines. Want one, but don't have one so I'll leave you lot in peace now! 😄