use write instead of print to avoid nil in empty files