updated filter function to output to file