In his Second Forward, on p. xvii, Stephen King writes:
"Fiction writers, present comapny included, don't understand very much about what they do -- not why it works when it's good, not why it doesn't when it's bad."
This is a statement that contains more truth than fact. There is definitely a sense that, since most writing is done in a vacuum, the author isn't going to know what does and doesn't work until the book is read, at least by himself, if not his first readers.
But writers know what works, at least the good ones do. They know what word to choose to achieve an effect. They know how to structure a book, or pace a scene. They know how to bring their ideas to life through words.
And they know what doesn't work. That's what rewriting is for. An author can read his own work, before it even gets to a reader, and identify things that are working and things that aren't. He can't find all of them, but he can find some.
But in that moment of creation, it's true, you don't know. You sit there in front of the screen and try. You bring yourself, your vocabulary, your sensibilities to the page, but in that moment of creation, you don't know whether it will work or not. It takes time, distance, a lot of patience. I guess the goal is to create more that works than doesn't.