sort is a filter. It reads input, modifies data somehow and prints output. grep is also a filter.
Usually a filter works by reading its standard input and writing to its standard output.
In case of … | grep … | sort -u > special_page_names the standard input of sort comes from grep and the standard output of sort goes to special_page_names. You requested this by using | between grep and sort, and by using > special_page_names at the end.
The syntax sort -u special_page_names tells the tool to ignore its standard input (in your interactive shell this is the terminal, standard input inherited from the shell) and read special_page_names instead. The standard output is not redirected; it's the standard output inherited from the shell, usually the terminal, in your case the terminal. The data flew from special_page_names to your terminal.
If you want to save the output of sort -u special_page_names to a regular file then one way is to redirect the output of sort, like in the first case. Do not redirect back to special_page_names though; choose another file.
sort -u special_page_names > special_page_names_sorted
There are tools that can modify the file they read (e.g. text editors). There are filters with an option to overwrite the file they read (e.g. sed -i). You can make sort write to the same file by specifying the file both as an option-argument to -o and an operand:
sort -u -o special_page_names special_page_names
sortprint something else than you expected? What exactly? Or did you expect the tool to modifyspecial_page_namesmaybe? – Kamil Maciorowski Mar 12 '22 at 16:21