Added error catching to the file creation step