The primary reason for performing an HSG is to investigate the causes of infertility. It helps determine whether the fallopian tubes are open or blocked and assesses the uterine cavity for any abnormalities such as fibroids, polyps, or congenital malformations. Additionally, an HSG can be used to confirm the success of a tubal ligation or to check the patency of the tubes post-surgery.