Getting null out of perfectly working script

So it might be a obvious answer but i’ve been trying to solve this for five days and i’m not familiar working without debug system. I can’t find where is the problem and why it is not giving me the output. When i wrote this script in console app it works perfectly but when i try to convert it to gh script it returns only nulls. I’m open to any suggestions or changes. Thanks.