Make sure output file is opened in write mode