Serial_TX/RX, USBTX/RX, PA_2/PA_3 and D0/D1 are all aliases of exactly the same pins: You didn't actually change your program :).
They will always go to the virtual serial port. It is also possible to route them in addition to that to D0/D1 (PA_2/PA_3). I think in the Nucleo manual it is shown which jumper/connection you need to make to have that connection work.
Some background: A long time ago, in a galaxy far away, someone made the Arduino platform. This made alot of people sad :P. (Mainly that the Arduino pinout isn't on the 2.54mm grid because someone worked late, made an error, no one catched it, and now we are all stuck with off-grid Arduino connectors). The Atmega used for the Arduino only has a single Serial connection on one set of pins: So it needed to be shared between the virtual one, and D0/D1. On Arduino you can use either set by default, but obviously not both at the same time.
Now fast forward to ARM boards with Arduino layout, and manufacturers simply don't realise that that sharing of the UART is not a feature, but an unwanted necesity. So they implement the same, even though it is stupid and makes no sense. To be fair: Freescale also did this initially, but they finally realised it was actually pretty stupid and their newer boards use a different UART with different pins for the virtual com port.
I have the Virtual comm port running ok in this code below:
but when I try to use the true serial port, UART PA_2 and PA_3 as coded here below, the data is still coming out of the Virtual comm port.