In the scene where Sean starts talking about his dead wife and her farting antics the lines were ad-libbed by Robin Williams, which is why Matt Damon is laughing so hard. The scene took everyone by surprise. According to Damon in the DVD commentary, this caused the cameraman to laugh so hard that the camera can be seen moving up and down slightly.

Meeting between Damon, Affleck, and Harvey Weinstein (as told by the latter on the Graham Norton Show)

Weinstein: ‘I only have one really big note on the script. About page 60 the two leads, both straight men, have a sex scene. What the hell is that? I don’t get it.’

Damon-Affleck: ‘That’s the scene we wrote to see if guys like you read the script because every studio executive we went to hadn’t read it. You’re the only guy who brought it up so you get the movie.’