Since Shakespeare left behind no personal accounts of his life—no letters, no journals, no essays—we have to use educated guesses as to why he wrote any of his plays. Scholars such as David Bevington believe Shakespeare wrote it near the time of its performance in 1604, when Shakespeare's players performed it at the court of James I. Apparently, if this timing is correct, Shakespeare wanted or needed a new play to perform for the king. He may have come across the story idea in an Italian drama called Cinthio by Giraldi, written in 1565 and translated into French in 1584, which features characters with the same names. The warfare between the Europeans, who were Christian, and the Muslim Ottoman Empire was on people's minds in the sixteenth and early seventeenth centuries, and a play starring a Moor and set in Venice might have seemed enticingly exotic enough for Shakespeare. Shakespeare himself would have been turning 40 in 1604, and it is likely that he too had concerns with entering middle age (and 40 would have felt older then than now) similar to those plaguing Othello, who fears he is too old to hold the affections of his much younger wife.
As always, Shakespeare was a great chronicler of the times. Venice was an important trading post and link between Europe and the East. At the time the play was written, there would have been ambassadors from Venice and beyond visiting Elizabethan England. Shakespeare would have enjoyed studying these 'exotic' strangers. Othello himself is referred to by Shakespeare as 'an extravagent, wheeling stranger' and this comment may have been coloured by Shakespeare's observations. The other answer of course is that, ever the magpie, Shakespeare 'borrowed' the tale by Cinthio called Hecatommithi, but adapted it coloured it according to his own fancy.
Some scholars believe Shakespeare based Othello on a short story called Gli Hecatommithi, which was published in 1565 by Geraldi Cinthio. The story dealt with the unfaithfulness of husbands and wives. Shakespeare might have found this theme excellent material for a stage play.
Shakespeare was probably also aware of accounts of wars between Turkey and Venice in the fifteenth and sixteenth centuries (Othello is general of the Venitian armed forces).
The plot allowed Shakespeare to explore issues of jealousy and deceit in the context which it can be most powerful -- that of a husband and wife.