One thing you should definitely keep in mind is audience- who your writing is aimed at (e.g. a letter to a company would be formal, a text message to a friend on the other hand would be informal) and another thing to keep in mind is purpose- why you are writing the letter/text, for example if you are writing to your boss saying why you should get a promotion. Purpose isn't overly important and tbh I wouldn't think of it as something to really distinguish whether write formally or informally. But I hope it helped :)