I can't get the desired output voltage
The voltage at the gate of the NMOS switch is on the low side, to fully switch on an NMOS you generally need a \$V_{GS}\$ of at least 3 V to switch the NMOS on. In your circuit the NMOS only gets: \$V_{GS}\$ = 3.3 V - 3 V = 0.3 V (that is if the NMOS was properly switching which it is not, the actual \$V_{GS}\$ will be more than 0.3 V because the voltage at the source will be less than 3 V) so the NMOS isn't going to be fully switched on and the NMOS is not going to operate as a switch. Instead it will work as a "source follower". The circuit can still work but it will be inefficient. The MOSFET will get warm when you're switching large currents (like more than 100 mA).

Why don't you use a P-channel MOSFET instead? A PMOS is much simpler to control in a "high side switch" like yours. Also have a look in this document for some examples and explanations.

Another tip: Use a dedicated module or IC.

Modules that take +5 V and output an isolated 12 V are available. Since the 12 V output is isolated, you can connect its + 12 V to your ground and then you would have the -12 V you need.

Also inverting DCDC converter modules exist, these do not have an isolated output but (like your circuit) take a positive input voltage and convert it to a negative output voltage. Search for: "Inverting DCDC"

Also ICs like the common LM2596 can be used to generate negative supply rails. In the datasheet of the LM2596 there's an example schematic on page 13 showing a circuit to generate -5 V. It can be adapted to output -12 V by using the 12 V version of the LM2596 or the adjustable version with the proper voltage divider.

Also note that your circuit can never output an exact -12 V as it has no feedback, the output voltage will depend on how much you load the circuit.

Edit:

You're shorting the source of the NMOS to Ground through the RPi's ground! The circuit can't work that way. Study some working designs to learn how this should be done.