I know my title is not much self-explanatory but let me try to explain it here.
I have a file name test.txt
which has some duplicate lines. Now, what I want
You can use the sponge utility from moreutils to soak up standard output before writing the file. This prevents you from having to shuffle files around, and approximates an in-place edit. For example:
sort -u test.txt | sponge test.txt
Using your corpus, this results in the expected output.
$ cat test.txt
AAAA
BBBB
CCCC