Heat/freeze treating will obviously kill any fly larvae that are present in the substrate, but it will also kill beneficial bacteria and fungi that are actively breaking down lignin. There's actually a huge amount of debate as to whether or not "sterilizing" substrate is beneficial, pointless, or potentially harmful. Take a look at any of the big time breeders in Europe and you'd be hard pressed to find a single one that sterilizes their materials.
You've got to understand that the substrate we use in breeding beetles is in and of itself, a living organism. It's full of a multitude of bacteria, fungi and (generally harmless) mold. All of these things add to the substrate and continue breaking it down. As for the flies themselves, they don't harm anything and are a minor nuisance at worst. If you've got them, you'll never be completely rid of them. Populations wax and wane with seasonal fluctuations, I always seem to have more in the winter.
Either way, small Dipterans are just a part of the hobby, and in my personal opinion, attempting to sterilize every last bit of substrate is asinine and more of a headache than an actual help.