> > I mistyped the script's extension as .txt rather than .sql.
That does not matter, that is more for user convenience in figuring out what the files are for.
I think all that is being said is the error was a simple typo, choosing the wrong file to execute. Not reading the error message was the real issue, not a failure to understand how psql scripting works.