[FIX] Flush output file before closing it for texture caching

This might solve the freeze issue when precaching.