This error can occur when you move the BEAM-DIMAP file to another location but you forget to move the corresponding data directory.
A BEAM-DIMAP consists of a *.dim file and a *.data directory.
Regarding thiw writing issue.
You mix to different writing scenarios. Yes, this API can be confusing, I know.
You can either replace the writePixels by setPixels call. In this case you don’t need get and set the writer before.
The other option is to remove the ProductIO.writeProduct() and call instead
writer.closeIO()
check also this post:
Problem saving product as HDF5 - development / python - STEP Forum (esa.int)
and especially the link to the ndvi example on github.
There are also a few more examples:
examples at master on GitHub