These primordial, undifferentiated parts develop differently depending on expression of certain genes and certain hormones. There's lots of genes and hormones involved in this process, and they determine whether the paramesonephric ducts or mesonephric ducts will regress, and whether the external genitals will develop into a penis and scrotum, or a vulva and lower vagina.