Write to file only when output has been generated