The chmod doesn't require the file to be opened. I'd move this out of the context.