Doesn’t alternating between writing test code and production code prevent you from entering flow?

No. The steady progress that TDD allows you to make and the feeling of safety that you get are more likely to put you in the state of flow.

Book References
Read more about this topic in Developer Testing: Building Quality into Software:

  • Chapter 14: Test-driven Development—Classic Style, page 191.