added fclose to writeFile

need fclose to avoid running out of file handles