This law would be unconstitutional. There is a well established constitutional right to travel and relocate. In general, a state can't burden that, partially also under the doctrine known as the dormant commerce clause.
There are quite a few laws that do make it illegal to cross state lines for a particular purpose.
For example, the Mann Act (also known as the White-Slave Traffic Act of 1910) is a federal law that criminalizes the transportation of “any woman or girl for the purpose of prostitution or debauchery, or for any other immoral purpose.”
But, those laws are almost always federal laws that are using the crossing of a state line as a trigger to show that the activity involves interstate commerce, which is something that Congress is expressly authorized to regulate by Article 1, Section 8, Clause 3 of the U.S. Constitution.
While states can regulate commerce in a way that incidentally and unavoidable impacts interstate commerce (which almost everything does), unlike Congress, states can't prohibit their citizens from engaging in interstate commerce or interstate travel as a result of these twin doctrines.
The main exception is a requirement in a pre-trial release order in a criminal case, or in a custody degree, prohibiting someone from leaving a state during the pre-trial or custody litigation period respectively, to prevent a court from losing jurisdiction over a party to a lawsuit during the pendency of that lawsuit in a situation where the court already has broad authority to detain someone (in the case of a criminal case where there is a pretrial release) or to say where a child is supposed to be physically (in the case of a custody dispute).
The authority of states to regulate interactions that necessarily involve interstate commerce is very limited and the dormant commerce clause basically reflects that implicit limitation.
This said, an outcome motivated set of judges could certainly decide to create an exception to the right to travel, abrogate the right entirely, or discard the dormant commerce clause entirely, if they could marshal (in the case of appellate courts) majorities of judges to overrule these precedents.