Don’t write it down until it’s the same three times.
I learned this rule from others, especially Alice Parker, who has written with her usual clarity about her process in her books.
As I’m writing, I’m constantly singing (shakily) and playing (barely passably) whatever I’m working on. And until it comes out the same three times in a row, I know that it’s still in process. If it’s in process, there’s not much good in writing it down.
Now, you might protest that your musical chops aren’t up to snuff with your compositional chops – that you can’t play everything you can compose. And that’s true for me, too. But I can sing, fake, and, most importantly, audiate what I’m writing. Even when my clumsy fingers hit the wrong keys, I work hard to hear what I intended. (I’m also working hard to hear voices, or whatever instruments I’m writing for, rather than keyboard sounds…)
It doesn’t work to notate it and then let the notation software play it three times; something about putting it into Finale or Dorico or Sibelius fixes it in the mind, making it more difficult to change. Letting it settle – even one bar at a time – until it’s the same three times is something that will make your writing truer.