I have created a .pgpass file in my home directory which looks like this
.pgpass
localhost:5432:somedb:someuser:somepass
I am using a shell scr
Did you try specifying the host, user, & db?
pg_dump -U someuser -h localhost somedb > directory/somefile.dump