Redirecting a pipeline into the file it reads empties the file first.
sort -u list.txt | sponge list.txt
With sort -u list.txt > list.txt the shell truncates the file before sort reads it. sponge soaks up all input and only then writes the file. It comes with the moreutils package. Use sponge -a to append. The data sits in memory or a temporary file until the input ends, so a failing earlier command can still overwrite the file with partial output.
Further reading: sponge manual page