Added file writing method