Flies and their larvae, which look like white grubs, can be part of the decomposition process. If the flies don't bother you, you don't really have to manage your pile to keep out flies. However, most people don't want to breed flies in their compost piles.
Flies are most active in wet kitchen scraps.
Keep all kitchen scraps tightly covered so that flies can't lay their eggs in the compostables. Make sure to bury scraps deeper in the pile, or cover with at least 4-6 inches of brown cover. Also, flies will be less attracted to a very hot pile.