Here is an example function which divides the list of rectangles into rows, the total width of each row being <= 130.
In[1]:= rectangles={{25,22},{40,28},{25,22},{31,23},{31,23},{40,28},{40,28},{25,22},{25,22},{31,23},{31,23},{31,23},{40,28}};
splitIntoRows[rows_, row_, rects_] := If[rects == {}, Append[rows, row],(*Done*)
(*Otherwise continue constructing a row*)
If[First[Total[row]] + First[First[rects]] <= 130,
splitIntoRows[rows, Append[row, First[rects]], Rest[rects]],(*Then we can add another rectangle to the row*)
splitIntoRows[Append[rows, row], {First[rects]}, Rest[rects]]]];(*Else we must start a new row*)
rows = splitIntoRows[{}, {First[rectangles]}, Rest[rectangles]]
Out[2]= {
{{25, 22}, {40, 28}, {25, 22}, {31, 23}},
{{31, 23}, {40, 28}, {40, 28}},
{{25, 22}, {25, 22}, {31, 23}, {31, 23}},
{{31, 23}, {40, 28}}}
Study that function. Try to understand the reasoning. See how the parameters control the function and construct the result. Make certain that it is correct for all possible input. Note: It silently fails to warn you if a single rectangle is wider than your box of if you give it an empty list of rectangles. It might miss other border cases that I haven't thought of, but I tried to keep this simple so you would be able to understand the strategy rather than wading through all the possible error checks that might otherwise be included. This seems a little like a homework problem for a first functional programming class.
Now could you consider constructing a function, perhaps using Piecewise or some other way of determining the minimal position for a rectangle, which would take the heights of the upper edge of a previous row of rectangles and correctly dealing with a starting state of an empty box, which gives the height of the upper edge of each new rectangle in a row?
I do not know what options you have for the positioning of the next rectangle in the box, but if I just do left-to-right and then bottom-to-top with each as closely packed to the lower left as possible then I don't think I see those rectangles fitting into your box.