Util function pre-request scripts in collection doesn't execute update variable

I have below utils function in a pre-request scripts in a collection

utils = {
    setCreateUpdate: function (json_body, uri_var){
        uri_value = pm.environment.get(uri_var);
        console.log(`Variable:${uri_var} with value:${uri_value}`);
        if(uri_value){  
            json_body.id = uri_value;
            pm.request.method = "PUT";
        }else{
            pm.request.method = "POST";
        }
        console.log(`Method:${pm.request.method}`);
        pm.environment.set("json_body", JSON.stringify(json_body));
    }
};

pm.environment.set doesn’t work in the function but it works if I return the value and set in the β€œpre-request script” of the request.

Is there any limitation context where global or collection functions can’t update variable?

Thanks