If I want to write something in a scale or improvise, do I need to memorize all of its positions on the fretboard or is there any other method? How do the pros do it?
Like Josh says, having a "toolkit" of licks and patterns and shapes is the start of it and can get you going, but the only way to really get good at improvising is to do it. A LOT. Until you can listen while you play and hear parts you like, you need to record yourself doing it (nothing fancy - back in the day, a simple cassette recorder 10 feet from the amp was fine) and listen back to see what you liked, and then remember how you did it.
Over time, you'll see that you suck less and less at it, have fewer times you "blank" on what to do next, and have fewer missed notes. But there will ALWAYS be stuff you improvise that didn't work out right - nature of the beast.