Write to file.
sort before writing.