Fixed mail ordering problem, needed to close file after writing to it