.beam files are not entirely portable. Erlang VM cannot load files compiled by newer version of OTP, or too old of a version.
I’m using .beam as script file
Common solution to your problem is escript, a type of an archive that can include multiple beam files, as well as Erlang runtime. Erlang runtime comes with an escript executable that knows how to extract and run these archives. rebar3 supports building escripts.