Move chmod to after the file has been opened