I solved the problem by replacing non-printable characters to nil, before writing to XML file. My regular expression is as follows.
in reply to Re: XML::Simple parser error : Input is not proper UTF-8, indicate encoding
in thread XML::Simple parser error : Input is not proper UTF-8, indicate encoding
# following is a code to remove non-printable characters in string i
# this pattern won't remove newline char