Section 5C. The comptroller shall annually, on or before October 31, certify to the secretary of administration and finance the amount of the consolidated net surplus in the budgetary funds at the close of the preceding fiscal year. Except as otherwise provided by law, the amounts so certified shall be transferred to the Commonwealth Stabilization Fund. This transfer shall be made from the undesignated fund balances in the budgetary funds proportionally from those undesignated fund balances; provided, however, that no such transfer shall cause a deficit in any of those funds. Before certifying the consolidated net surplus under this section, the comptroller shall, to the extent possible, eliminate deficits in any fund contributing to the surplus by transferring positive fund balances from any other fund contributing to the surplus.