Flush output file after each script recording event

This avoids losing data when recording programs that get terminated with a
signal.