openxlsx::write.xlsx generates a broken file

Welcome to RStudio Community!
Could you please provide reproducible example? See this post on what is this and how to do it - Reprex.

I had similar problems with XLSX files when I am writing Excel formulas in one of data frame columns and making mistake in formula in process. So my guess without seeing reprex is that data frame content is not something that could be saved inside XLSX cells.

Reprex will definitely help to provide you a better answer.