How does one balance between working on a research problem and writing up the results?
Do everything you can to reduce the exploratory nature of the data analysis.

Plan exactly what results you are going to need for your manuscript, what the tables will be, what the figures will be, how they will be formatted. Then when you get to the data analysis, you can be extremely focused, concentrating only on what's essential for your work.