It would be useful to know, which version of LAMMPS this is with (the date printed when you launch LAMMPS).
it also would be helpful, if you would provide a simple and complete example that demonstrates the issue reliably and quickly.
there are some known difficulties with line-buffering vs block-buffering when redirecting output, since PyLammps captures and interprets LAMMPS output and thus is dependent on line-buffering as far as i know.
if you want to play it safe, use the more low-level “lammps” python class, which is not affected by this.
i am copying richard berger, the author of the PyLammps class, who might be able to comment further.
Redirecting the output of LAMMPS when using PyLammps is problematic. The solution is to use stdbuf, using python3 or setting the environment variable PYTHONUNBUFFERED=1