How did nerd and dork become synonyms?
It's probably more the case that they begin as terms with a similar meaning, and only later diverge.
DORK is noted as "a penis" (from 1961) and "a fool" (from 1965) in Green's Dictionary of Slang.
NERD there is given as "(orig. US) an unpleasant, insignificant or dull person" (from 1951).
That rather misses out the nuance whereby it could be said that nerds are dorks with brains.
It seems to be the case that "nerd" begins as a general pejorative, and only later develops the "studious but socially unacceptable" sense. Looking at the cites given in GDoS, it looks as if the shift in the meaning of "nerd" begins to happen in the late 1980s.