Answer: Based on your description, I think the balls are probably slow release fertilizer which can last as long as six months or more in the soil depending on what type was used.
The fly, if it was quite small or seemed like a fruit fly, might have been a fungus gnat. These breed in overly wet soil such as when plants are overwatered. Their larvae live in the soil and usually eat organic matter but can sometimes damage plant roots as well.
The solution is to allow the soil surface to dry out between waterings to prevent them from breeding, and/or you can use a soil drench such as Gnatrol to kill them in the soil. If you have a plant that specifically requires constantly wet soil, place a layer of sand or gravel on the soil surface. This will dry out quickly while allowing you to keep the underlying soil wet.
I hope this helps.
Q&A Library Searching Tips