The most likely cause of contracting HIV from the provided options is:
He shared a dirty needle when injecting drugs with a friend.
HIV is most commonly transmitted through the sharing of needles or syringes, unprotected sexual contact, and from mother to child during childbirth or breastfeeding. The other options listed are not ways that HIV is transmitted.