What flies are we talking about here? Fruit flies or larger flies like houseflies and blue bottle flies?
For fruit flies there's no need to refrigerate them. Just give the lid a good tap or two, open the lid, tap on the bottom to get a couple flies out, tap again to make them fall back down and then put the lid back on. Fruit flies (and its maggots) can be refrigerated to slow them down, I haven't tried refrigerating them for extended periods of time though.
For larger flies you can refrigerate them as long as you want, they will not die. Blue bottle flies can take about 6-10 min in the freezer without any problems. The maggots and pupa of blue bottle flies/house flies can be refrigerated as long as you want, though they will either hatch or start going bad at about 4 weeks (house flies) and 8 weeks (blue bottle flies).