I worked it out. There is no encoding issue. It was in PHP array. PHP array returns empty for Null value. var_dump() returns Null value as Null but print_r() returns empty. I used the following code to get Null value as Null.
if ($cell==Null)
{
$values .= 'Null,';
}
But PHP interpret 0 and false as Null also. So the above code returns 0 and false as null also. Here I changed it as below and got it worked.
if ($cell===Null)
{
$values .= 'Null,';
}