I asked a somewhat related question recently and then became interested in this one: how many people are required, on average, until 3 share a birthday? More generally, if we have $M$ bins, what is the expected number of balls we must toss before some bin contains exactly 3 balls?

The straightforward techniques used in the question cited above seem hard-to-apply here because the number of ways to obtain configurations with 2-balls-or-fewer is quite a bit messier now.

Question: what is the expected number of balls needed to obtain a bin with 3 balls in it?

To expand a bit on the "messy" comment above: the EGF for the number of ways to toss $n$ balls into $M$ bins with no bin containing more than 2 balls is $$(1+z+z^2/2)^M$$

So, for example, if we have $M=3$ bins, the number of ways for $n$ balls to be arranged (with no bin having more than 2 balls) is found by taking the $n$-th coefficient of $$(1+z+z^2/2)^3 = 1/0! + 3 z/1! + 9z^2/2! + 24z^3/3! + 54z^4/4! + 90z^5/5! + 90z^6/6!$$

So if I want the number of 4-letter words from the alphabet $\{a,b,c\}$ where no letter occurs more than twice, it's the coefficient of ${z^4/4!}$ or 54 according to this formula. We can verify this directly by noticing there are three 4-letter words with all characters the same (aaaa, bbbb, and cccc). For the words with 3 letters the same and one different, there are 4 ways to choose the position of the different letter, then 3 choices of what that letter is, then 2 choices for the three letters that match. The total number of 4-letter words is therefore $3^4=81$, so we have $81-3-4\cdot 3\cdot 2 = 54$. Of course this gets complicated as $M$ increases.

How you get from this EGF to an asymptotic estimate of the expectation is beyond me.

Note: Byron's answer below settles this. For anyone interested, this fully generalizes to "k-wise collisions" using

$$E(M,k) \approx \sqrt[k]{k!}\ \Gamma(1 + 1/k)\ M^{1-1/k}$$

where setting $k=3$ yields the result in Byron's answer below. Of course this is an asymptotic result and gets better as $M$ increases. For $M$=365 this formula yields about 82.87, whereas the correct answer is about 88.73891.