It’s not at all unusual for small children who are shy or alone to make up imaginary friends. Actually, most kids go through a stage where they make up a constant companion. Kids who do not have other kids in their lives keep this going longer — usually until they start school and start to make friends with classmates. These real life friends take the place of the imaginary ones.
You’ve said you are shy. My guess is that for some reason you weren’t able to connect with other kids your age when you were young and so you kept the imaginary scenes going. Now it’s become a habit. It’s hard to shake it because you are still shy and you haven’t developed the skills you need to connect with peers. You then retreat to the “friends” in your head who accept you and who aren’t a bit threatening to your sense of self.
You were correct to name this a “cycle.” It is. You try to connect with people. It doesn’t go well. You retreat to the imaginary — which makes it more likely you won’t learn what you need to learn to connect with people. And so on and so on.
To break the cycle, you need some new social skills. I suggest you consider getting into group therapy. In group, you will have the opportunity to learn those social skills. The rules of the group will provide the safety you need to get out of your head and to try out new ways of relating. Feedback and support from the other group members and the therapist will help you gain the self-confidence you need to develop real life relationships.
And — by the way — you don’t need to abandon your imaginary friends. You may have the makings of a terrific writer. Give yourself a set time of day and length of time to write about your scenarios. Confine the activity to that time frame to make sure you don’t fall back into the cycle.
I wish you well.