In fact, while Robert Downey Jr. was responsible for that jab at Spider-Man, Tom Holland similarly got a moment to shine during production, as well.
This scene stands out as one of several instances of improv from the set of Avengers: Infinity War that made it into the final cut of the movie.
Later in the film when Spidey begins to fade away, his tearful pleas of “I don’t want to go,” were reportedly made up by Holland.
Marvel Studios hones these films down to a science, but it’s reasonably clear that directors Joe and Anthony Russo don’t mind playing around and letting the actors explore the scenes to find some moments of improv, regardless of whether the lines are incredibly funny or incredibly dark.