Did you try Base.Libc.flush_cstdio() before exiting redirect_stdout?
Base.Libc.flush_cstdio()
redirect_stdout