lo: before or after the verb
Why do some sentences in spanish place the word "lo" in front of the word and sometimes, it is attached at the end of the verb? e.g. Escibelo.
Your question deals with the use of the Direct Object Pronoun and I would suggest that if you are interested, you might want to read the useful reference article that is available on this site.
As to your particular question, the answer is rather simple in that when you have a positive command (escribelo - write it) you always append the Direct Object Pronoun to the verb.
You will also find that the object pronoun can also be appended to infinitives and gerunds, but in this case it is optional.
Infinitives: Quiero escribirlo - I want to write it.
..............Lo quiero escribir - I want to write it.
Gerunds: Estaba escribiéndolo - I was writing it.
..............Lo estaba escribiendo - I was writing it.
Note: When you attach it to the gerund, it is necessary to accent the penultimate syllable of the gerund to keep the stress in the proper position (see example)
Besides the Direct Object Pronoun link, you might also want to try the Indirect Object Pronouns and Object Pronouns Together reference articles to round out your understanding of the subject.
Object or reflexive pronouns may optionally be attached to the end the end of verb infinitives and present participles (gerundio). With affirmative commands the must be appended to the command and with negative commands they must precede the command.
¿Quieres hacerlo? (stress must be maintained where it was before the pronoun(s) was attached so often a tilde must be added).
¿Lo quieres hacer?
Ella estaba leyéndomela.
Ella me la leyendo.
You mean "Escríbelo." There are just 3 verb forms where you will find the direct object pronoun (say, lo) at the end: infinitive=ex:escribirlo, present participle=ex:escribiéndolo, & the affirmative command=ex:escríbelo.
In the case of infinitives, present participles, and affirmative commands you can attach the direct object pronoun to the end of the verb, or you can put it before the first verb.
Estoy limpiándola. La estoy limpiando. (I am cleaning it.)
Voy a hacerla. La voy a hacer. (I am going to do it.)