Fruit flies are attracted by the smell of rotting fruit, food, and sweet liquids. While they can be brought into your home in shopping bags, they can also find a way to enter your house from the garden if the smell is strong enough.
Fruit flies are experienced and resilient insects that have keen senses to find their next meal, so even one piece of fruit left on the kitchen counter can attract many flies.