But don't know why still, around 6 out of 10, scenarios fails completely in browser
Well, the new code you posted you use print $cgi->header(); but this will never prints a session cookie, CGI.pm doesn't know anything about CGI::Session, see Re: CGI::Session "cache" issue, use $session->header, otherwise there is no session . no cookie means no sessionid means no session -- it may exist on the server, but the browser doesn't know anything about it (doesn't exist)
fails completely in browser and command line mode.
how are you passing the sessionid on the commandline?