Test: test-headers: get working in VPATH build
"make distcheck" does a VPATH build (i.e. srcdir and builddir are different),
so make test-headers able to work in that situation by passing in the location
of the source directory and using a generated temporary file name for the
generated file.
Also do a bit of shell best practices while we're at it