Pipe psql timing to file
You can do this by piping the query into psql, then grepping the output, like so:

postgres@winterspring:~$ cat foo.sql
\timing on
select * from foo;
postgres@winterspring:~$ psql &lt; foo.sql | grep "^Time:"
Time: 0.505 ms
postgres@winterspring:~$


Redirect just the timing to a file if needed:

postgres@winterspring:~$ psql &lt; foo.sql | grep "^Time:" &gt;&gt; timing.txt


The grep will have a slight performance impact.