In a writing session of happy engagement, you are focused not on your ego (either negatively or positively)but on the work in front of you. We've already shown that seemingly "positive" ego can also be detrimental. Having a "strong ego" can mean two things: not worrying about the ego one way or the other, or having an exaggerated sense of self-worth that is, consequently, easily bruised. (The latter is really a form of weak ego, not a manifestation of a strong one!)
So the kind of inner monologue you will hear in a mood of happy engagement is more like this: "That paragraph is almost done, but something is missing at the end... Oh, I see, that last sentence needs to be the topic sentence of a paragraph of its own... How should I end that paragraph, then?... I need a better transition..."
It might help to realize that you don't need to worry about getting to a zone of perfect egolessness. That may never even happen. As long as your main focus is on the work rather than on your self, you can simply accept that you will still have distracting thoughts related to your adequacy or inadequacy. If you spend too much energy trying to banish those thoughts, you will be doubly distracted: "Gee, this egolessness is hard to achieve, I am horrible at this...I'll never get this right." Instead, you could imagine yourself saying: "Oh, I just had one of my 'underconfident' (or 'overconfident') moments... Not very helpful, so I will return to the business at hand."
It might also help to know that everyone has moments of self-doubt and / or overconfidence. The negative thought is not, itself, a sign that you are deeply flawed or doomed to failure. Thinking you are brilliant, by the same token, does not mean that you are. It is just a natural reaction when things are going well.
Believing in yourself is fine. Earnest exhortations to have a positive attitude, however, are not very useful, because a positive attitude cannot be willed into existence. If crippling negative thoughts are dominating your inner monologue, you cannot just replace them with a different, more positive sort of self talk. If you are in state that the ego is out of control, no amount of "writing advice" will really help. Instead, the remedy is to analyze the reasons behind the negativity. If you experienced "happy engagement" in the past, what was different about that time? Maybe there was no pressure for tenure? Maybe you had a better mentor at the time?