Preventing file write when readFile fails