Heuristic for Tournament Scheduling
I would suggest that you use an integer linear programming (ILP) solver or a SAT solver.  This will probably be easier to formulate as ILP, so start there.

Let's check whether it is possible to ensure that no group ever gets teamed up with another group more than once.  (We'll ignore the bonus condition.)  Define a zero-or-one integer variable $x_{g,t,r}$, with the intent that $x_{g,t,r} = 1$ if group $g$ plays in team $t$ during round $r$, and $x_{g,t,r} = 0$ otherwise.  Now we can write some linear inequalities to capture the constraints on a valid solution:


$0 \le x_{g,t,r} \le 1$ ensures that each $x_{g,t,r}$ is zero or one.
$\sum_g x_{g,t,r} = 3$ ensures that exactly 3 groups are assigned to each team in each round.
$\sum_t x_{g,t,r} \le 1$ ensures that no group is assigned to more than one team in any given round.
Arbitrarily choose 36 groups to play 5 games; for those groups $g$, the linear equality $\sum_{t,r} x_{g,t,r} = 5$ ensures they will play 5 times.  The other 6 groups will play 6 games; for them, enforce the linear inequality $\sum_{t,r} x_{g,t,r} = 6$.
For each pair of groups $g,g'$, we enforce the linear inequality $x_{g,t,r} + x_{g',t,r} + x_{g,t',r'} + x_{g',t',r'} \le 3$ for all $t,r,t',r'$; this ensures that $g,g'$ never play together on the same team more than once.


Feed this system of inequalities to an ILP solver.  If it has a feasible solution, then you have found a valid schedule for your tournament.

If it has no feasible solution, next check whether there's a feasible tournament where no group ever gets teamed up with any other group more than twice.  Do this by replacing the last set of inequalities above with the following:


For each pair of groups $g,g'$, we enforce the linear inequality $x_{g,t,r} + x_{g',t,r} + x_{g,t',r'} + x_{g',t',r'} + x_{g,t'',r''} + x_{g',t'',r''} \le 5$ for all $t,r,t',r',t'',r''$; this ensures that $g,g'$ never play together on the same team more than twice.


If this doesn't have a feasible solution, check whether there's a way to do it where no group ever gets teamed up with any other group more than three times.  Do a linear search until you find the best solution.

Once you've found the best solution, now you can try to handle the bonus condition.  Let's say you want to see whether there's a way to do it where no group gets teamed up with another group more than once, and (here's the bonus condition:) no group has to wait more than three games.  The bonus condition is easy to enforce: for each $r$, simply add the linear inequality $\sum_t x_{g,t,r} + \sum_{t'} x_{g,t',r+1} + \sum_{t''} x_{g,t'',r+2} \ge 1$.  Now test whether that's feasible.  Of course, you can vary the waiting time (it doesn't have to be three games) to find the smallest waiting time possible.

I'd expect this might find a solution to your problem.  Modern ILP solvers are surprisingly good at solving many ILP instances, if there is sufficient structure -- and in this case I suspect there might be enough structure that off-the-shelf ILP solvers might work well.

There are variations possible to speed up the ILP solver, but I suspect that this straightforward formulation might just work with no tweaks or optimizations needed.  Give it a try!  It shouldn't be too hard to test out and see if it works.