I'll try to cut a long story short ...
The most text editors work with the default ANSI codepage (Windows-1252
in your case). Each character is represented as 8 bits (a combination of either 0 or 1). Have a look at the link. In the table you'll find character "§" in row A and column 7. That means A7 is the hexadecimal representation of that character in codepage 1252. Hence the following 8 bits (= 1 byte) are written to the file: 10100111.
The cmd.exe reads that byte and tries to translate it to a character. Cmd.exe works with ASCII though. It's codepage 437
in your case. Have a look at that table and find the character in row A and column 7
Now you should understand how it works. The content of the file is exactly the same but the character interpretation is completely different.
What I did in my first code is simple. The CHCP command without an argument displays the current codepage of your batch window (ASCII). Inside of the FOR /F loop I queried the registry to get the default ANSI codepage.
In the second code I applied these codepages. First I changed the codepage of the batch window to ANSI. Now the byte 10100111 is interpreted as § and assigned to variable p.
When I changed back to ASCII an internal process in cmd.exe converts the variable and you can display the § in the batch window.