Add file.Close() section. Move the output section to the end of main().