fclose should come before rm