Work out a filename and dump to file