optionally pipe output to a file. correctly, this time