Check if request is successful before writing data to the file