"There she paused for a while thinking...but the temptation was so great that she could not conquer it." - "Bluebeard" by Charles Perrault
"Lonelyhearts" draws inspiration from the tale "Bluebeard", originally a French folktale written by Charles Perrault in 1697.
Bluebeard is an immensely wealthy aristocrat, who is feared because of his ugly blue beard. He has been married several times, but his wives continue to die off, the reason for their untimely fates unknown. Bluebeard announces to his current wife that he must leave the country for a while and gives all the keys of his castle to her. He says she may explore the rooms freely, except for one small room beneath the castle. Of course, immediately after he leaves, the young woman is overcome with the desire to see what the forbidden room holds. Despite warnings from her visiting sister, she looks inside.
The wife discovers that the room holds the murdered bodies of her husband's former wives, hanging from hooks on the walls. Horrified, she drops the key into a pool of blood, picks the key up and flees the room, but the blood staining the key will not wash off. She reveals her murderous husband's secret to her sister, and both plan to flee the castle the next day.
Bluebeard returns home unexpectedly the next morning and, noticing the blood on the key, immediately knows his wife has broken her vow. As Bluebeard is about to kill his wife for disobeying him, her brothers break into the castle and kill Bluebeard at the last minute.
There are clear parallels between the story of Bluebeard and "Lonelyhearts". Bluebeard in the tale has the ability to woo women repeatedly despite his ugly features (much like the Bluebeard in the episode, though it's the result of pheromones rather than riches). Also, both hide their victims in the basement, though Billy Capra chooses to keep his victims alive for breeding, while Bluebeard kills his wives for reasons unknown.