ALSO, look at it from a psychological perspective.
Once you close your eyes, you said you can't help it. Why? Because you get a single thought. Then they persist and jump at you in forms of multiple thoughts, bringing you to give up to the temptation.
The first thing you gotta do is, once you close your eyes, try to fight the first thought you get. Dont think "I cant do this.. I shouldn't be doing this". The more you think about it and how you cant do it, you will be even more tempted to do it. THink "i dont want to do this!" and automatically push your thoughts away and CLEAR your mind or think about something else. Its not easy, but if you give in at the start, it wont even be much of a battle
You formed a habit. You brain automatically reminds you especially when you lay down at night. Now you gotta kill the habit. It wont be easy at first. But it eventually gets easier so remind yourself that. And remember, your lustful desire is only temporary. Its not even a real rewardd. Because as soon as you finish the haram way, itll come back.
So would you rather take the haram route when the desire will eventually come back? Or would you learn to master your mind so that you dont need a cheap way to CONSTANTLY satisfy a temporary desire that leaves on its own.
- - - Updated - - -
Also, try to distract your mind with a lecture or quran as you go to sleep.