I don't think they knew to have sex. I personally think that it all occured by experiment of the body and what it does. People continued to do it because of the pleasurable feeling they got from it and it turned out to what it is today - the reproduction of humans