changes in preg_replace. writing the encoded output into a file. not able to properly downlaoded the encoded file