Flush sys.stdout to prevent cursor jumping