fixed open flags
fixed file permissions
sizeof is still wrong in writeFile