added exit status when can't write the file