Does the United States Congress have the power to authorize a court to rewrite a statute to save that statute from constitutional invalidity?
Congress cannot delegate statutory rewriting power to the Courts in order that they can make the statute Constitutional. In Panama Refining Co. v. Ryan, the Supreme Court ruled that Congress could not delegate the power to prohibit certain excessive oil shipments to the president. In this decision, Chief Justice Hughes wrote:
The Constitution provides that "All legislative Powers herein granted shall be vested in a Congress of the United States, which shall consist of a Senate and a House of Representatives."
The Congress manifestly is not permitted to abdicate or to transfer to others the essential legislative functions with which it is thus vested.
Another case, A.L.A. Schechter Poultry Corp. v. United States (often known as the "Sick Chickens Case"), was decided that same year, and reached a similar conclusion. These cases have never been overruled, and as such, Congress remains prohibited from delegating its lawmaking abilities to other branches of the government.
However, Congress frequently assigns regulatory agencies the ability to create regulation, and no such assignment of regulatory authority has been ruled unconstitutional since Schechter and Panama Refining Co. This is because the Supreme Court has ruled that, when a grant of regulatory authority "lay[s] down by legislative act an intelligible principle to which the person or body authorized to [act] is directed to conform", Congress is not unconstitutionally delegating its ability to make laws.
This means that the existence of regulatory agencies does not imply that Congress can delegate the power to rewrite statutes as necessary to make them Constitutional. Lawmaking authority remains solely vested in Congress.
Just as Congress is prohibited from delegating its lawmaking authority, so are the Courts prohibited from ruling on a case where no controversy exists. Article III, Section 2, Clause 1 of the Constitution defines the areas in which the Courts have jurisdiction, and in each area an actual case or controversy must be present.
The "case or controversy" clause of the Constitution prohibits the courts not only from rewriting statutes, but from even issuing an advisory opinion on whether a law or action would be Constitutional were it to be implemented. When Thomas Jefferson, as Secretary of State, asked the Supreme Court Justices what conduct was permitted by the United States as a neutral party in a war between Britain and France, the Justices wrote back:
[The] three departments of the government ... being in certain respects checks upon each other, and our being judges of a court in the last resort, are considerations which afford strong arguments against the propriety of our extra-judicially deciding the questions alluded to.
All of this seems to suggest an absolute inability of the Supreme Court to make any changes to legislation in order to ensure its Constitutionality. It can only rule on laws or portions of laws as Constitutional or not, and only then when an actual case or controversy exists.
However, the courts have a small amount of leeway. If an otherwise Unconstitutional statute can be fairly construed as meaning something that is Constitutional, then the court can interpret it in that way. This technique was famously used by Chief Justice Roberts in National Federation of Independent Business v. Sebelius, in order to find the individual mandate portion of the Affordable Care Act Constitutional. After finding that the individual mandate could not be justified by the Commerce Clause, he decided that it could be construed as a tax, and would thus be Constitutional:
In answering that question [of whether the individual mandate is Constitutional] we must, if "fairly possible," construe the provision to be a tax rather than a mandate-with-penalty, since that would render it constitutional rather than unconstitutional. But we cannot rewrite the statute to be what it is not.
It's important to note that the courts do not consider this ability to construe to imply the ability to change what the law is, only to say what the law is. For example, in NFIB v. Sebelius, Justice Scalia (writing in dissent) felt that Roberts' construction of the individual mandate as a tax changed the law, and was therefore not allowed:
The Court today decides to save a statute Congress did not write. It rules that what the statute declares to be a requirement with a penalty is instead an option subject to a tax.
Therefore, the precedent is clear on this question. Despite the ability of Congress to narrowly delegate regulatory authority to certain agencies, it can never delegate the ability to write laws, especially not to the courts.
Finally, I think I should mention that almost all of this information came from the fourth edition of Erwin Chemerinsky's excellent casebook on Constitutional Law. If this is a subject that interests you, I strongly recommend checking it out.
Courts do NOT have the power to write statutory code. There is a distinct separation of power. If the Legislator gave control of writing statutory code, it would instinctively remove the power of the legislative branch.
There are three branches of government to contain the control of the most basic abilities. So no distinct person had the ability to both write law and dictate if someone was breaking said law. That power is only given to kings and dictators.