something like this should work, I see no need for the function.
[{"id":"081f859720887260","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","x":610,"y":4220,"wires":[["202cb4e226711627"]]},{"id":"202cb4e226711627","type":"change","z":"452103ea51141731","name":"HKL1-main_KW","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.value","tot":"msg"},{"t":"set","p":"payload.timestamp","pt":"msg","to":"$now()","tot":"jsonata"},{"t":"set","p":"payload.MeterId","pt":"msg","to":"HKL1-main_KW","tot":"str"},{"t":"set","p":"payload.Unit","pt":"msg","to":"KW","tot":"str"},{"t":"set","p":"payload.Type","pt":"msg","to":"energy","tot":"str"},{"t":"set","p":"columns","pt":"msg","to":"$join($keys($$.payload),\",\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":4220,"wires":[["f74dcac77d74f590"]]},{"id":"f74dcac77d74f590","type":"csv","z":"452103ea51141731","name":"test_csv","sep":",","hdrin":true,"hdrout":"once","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":false,"x":1000,"y":4220,"wires":[["33de82cd26ec61be","dd5a4a107ea99ebb"]]},{"id":"33de82cd26ec61be","type":"debug","z":"452103ea51141731","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1030,"y":4140,"wires":[]},{"id":"dd5a4a107ea99ebb","type":"file","z":"452103ea51141731","name":"","filename":"test.txt","filenameType":"str","appendNewline":false,"createDir":true,"overwriteFile":"false","encoding":"none","x":980,"y":4280,"wires":[[]]}]
Just add change nodes for each reading
Text file