Fix condition for file writing