Use temporary-file-directory instead of "/tmp"
Restore marks after sorting