checking identity to log errors, refactored logic
fixed call to write_tsv
provide ability to specify output filename