psql, getting a list of databases to be parsed by a script
I don't see how your two solutions are different...  Since it still has to actually CONNECT to a database instance to see what databases are there, I'm willing to bet the only different is HOW you are connecting.

psql -l -A -t


vs

psql --quiet --no-align --tuples-only --dbname=postgres --username=postgres --host=127.0.0.1 --port=5432 --command="SELECT datname FROM pg_database"


Try instead

psql -q -A -t -c "SELECT datname FROM pg_database"


This should use the default connection settings (database and login as local account, local connection, 5432 port).  If you really need to, then specify the user and database with -U postgres -d postgres .. but otherwise just leave the host and port unspecified.

I'm willing to bet the only reason psql -l -A -t isn't asking for a password is because you have that information in your .pgpass file.