Left/right sound localization is partially a function of "shadow" created by the head. However more important to localization is the pinna, the outer ear.
Sound enters the earhole directly AND reflects off the folds in the pinna.
This causes complex comb filtering. (cancellation) Our brain learns how to correlate sound direction with these complex filterings. It's quite amazing.
Some audio workstations (Logic) have "binaural" processing to try and emulate this effect. It can never be perfect because everyone's ears are shaped a little different.