I decide what should be written next only when I am writing that.
This called being a "pants writer" or a "pantser," meaning that you write by the seat of your pants. It's completely valid as a workflow, IF you are then willing to go back to the beginning when you're finished and edit with a firm, even harsh hand.
Just because it spews out of you doesn't mean the plot will work, the characters will be intriguing, or all the questions will be answered. So you will have to go back and tweak, fix, rewrite, and possibly unravel hack chunks of the story.
On the other hand, you can't edit a blank page. If you pants the entire thing, you will have a book to wrangle into shape.
I say go for it. Write what comes out, write to the end, and then go back and fix it afterward. Just remember that for a pantser, the editing and rewriting are part of your first draft process, not optional passes.