fix permissions, write file