Updated file writing