She modified their memories so they both believed that the two of them had been having an affair with Harry for months. The fact that they were roommates that lived nearby made everything easier for Hermione to arrange.