Improved error handling of write(task), updateFile(), and
writeToFile(newFileText)