What type of lumber should I use for narrowing a recessed hole in my bathroom wall, to be used for a new cabinet?
You could use almost any wood that happens to be the right thickness. Multiple pieces even - e.g., multiple layers of plywood.
However, I would definitely use screws rather than nails. Nails will hold just fine, but I find that screws with a decent battery-powered drill/driver are a lot easier than nails, especially when working in relatively small spaces.