The solution was to add a stripws option. After that all output XML files are indented properly because causing the issue whitespaces were removed. Please see the working properly XQuery below.
(: https://docs.basex.org/main/Options#stripws :) declare option db:stripws "true";
declare variable $input as xs:string external; declare variable $output_dir as xs:string external;
for $x at $i in doc($input)/Events/Event return file:write($output_dir || file:dir-separator() || "event_" || $i || ".xml", $x , map {'method': 'xml', 'indent': 'yes', 'omit-xml-declaration': 'no'})
Regards, Yitzhak Khabinsky