adds error check to csv file creation