The problem is not just about the thought is stuck in your head rather anxiety that you are feeling when ever that though comes into your consciousness awareness.
You could try CBT (graded exposure)
In this person is asked to make a list ending to most feared situations that is sleeping alone and starting from some one sleeping with you , to some one sleeping on different bed but same room, to some sleep in the hall and on and on .
They key is persistence and determination for getting rid off your fear.
Still if this not working, please consult a psychiatrist for further evaluation and management
Next Steps
Consultant psychiatrist
Health Tips
Key is persistent and determination