The difference is in the reference, what the sentence intends to denote.
'stay up late to do something' is indicating the reason for staying up late.
'stay up late doing' indicates the action, that took place and that has kept someone awake.
He stayed up late yesterday to finish his assignment. ( The reason)
He stayed up late yesterday working on his research ( the action taking place)