If you shine the light at all when you're too near to it, it'll lock on until it kills you. But as long as you're in darkness, or use your light a distance away, it seems to just move at random. It's pretty easy to avoid if you use the light very sparingly.