close the file written to and use && instead of the erroneous & in a comparison