During my last code review, there was a similar situation and my solution was to keep all the files open for writing.  It was pointed out that I should not do this, because the OS can only have so many filehandles open at the same time.  E.g., on compy, this number has hard and soft limits, respectively, of:

adro2179 ~ $ulimit -Hn
4096
adro2179 ~ $ulimit -Sn
1024

So, if a file had more than that number of samples, the script would crash.  I think explicit buffering is the way to go here.  Although it's true that the file objects have their own buffer, it is flushed on the file.close() (in this case, after every single sequence).