Tweak logic for writing prefix files to a cache in --build-only mode.

Just write a newline separated text file containing all the file names instead
of a json file.  We don't need json here, and json.dumps() doesn't even work
on 2.x in this instance -- it was raising a unicode/str error.
Fix what appears to be a stale-directory bug with --build-only.

Multiple calls to source.get_dir() appear to be the culprit.  Call it once and
re-use instead of repeatedly calling it.  This fixes --build-only on Linux
(Centos 5.x).