Implement file output (fixes #9).