Compass currently does not support loading files. You can either copy-paste the script as you suggested or you can run it with mongosh in the terminal.
Alternatively, if that’s something you do often and you are a VS Code user, I’d recommend checking out MongoDB for VS Code.