In my case, the problem was coming up because I had two database servers running on the same machine: [1] Postgresql 14 which uses scram-sha-256 and [2] Postgresql 9.6 which uses md6. So I needed to specify the port number, and it worked!
$psql -U postgres -d dbname -p 5523 -f *path/to/file*