Fix logic error re. opening output files.