received permission denied when trying to write to the file