Flush output to avoid data corruption