There are a couple of syntax issues with your code shown below:
How often would you dare to pass a detailed FLWOR expression directly as a function parameter instead of specifying an extra variable name or function call?
db:add("Test_DB", <root><contents>Another document example: {$X}</contents></root>, "my_test.xml")
Regards, Markus