It is not your fault, and really not such a big issue presuming common fly larvae, the piggie likely eats them, such things are like a treat. Meal worms and wax worms are feeders sold at pet stores, my trio loved them.
This usually happens when perishable foods are left in the cage and begins to decay.
Contaminated hay begins decay as well as beddings. that takes some serious neglect.
You might identify these, some few flies are parasites and not good for pets or humans.
Just clean the cage well on cleaning day being sure to get any eggs. This includes hides and food utensils, bowls etc.
When you give piggies perishable foods, change that out at least after 24 hours.
Keep hay in racks so it doesn't get contaminated and decaying.
Flystike is very unlikely unless you live in a region with parasitic flies, and then a vet can easily treat this.
Worst you could do is return this poor animal to the same environment that brought this on.