added function to write errors file heading and to avoid creating the file when no errors