What scripture is James 4:5 referring to? James 4:5 (ESV)
  Or do you suppose it is to no purpose that the Scripture says, "He yearns jealously over the spirit that he has made to dwell in us"?   


I don't know of an Old Testament passage similar to James's quote. What is he referring to?
There is indeed no Old Testament passage that contains those words, but there are a number of theories regarding what James was referring to. From Precept Austin:


  Ideas include (1) James quoted from some unknown apocryphal work (2)
  The quote is an unrecorded statement of James' half brother Jesus. (3)
  James quotes from some NT passage. (4) James was paraphrasing an OT
  passage. (5) James was not quoting a specific single passage, but is
  summarizing truths found in several OT passages. (6) Finally, some
  commentators (and Bible translations) do not treat the first half of
  verse 5 as a "formula" introducing a quotation but as a sentence which
  stands by itself. Several of the translations emphasize this latter
  view by dividing verse 5 into two separate sentences...
  
  
  Or think ye that the scripture speaketh in vain? Doth the spirit which
  he made to dwell in us long unto envying? (ASV)
  Think ye that the scripture speaks in vain? Does the Spirit which has
  taken his abode in us desire enviously? (Darby)
  Do you think what the scriptures have to say about this is a mere
  formality? Or do you imagine that this spirit of passionate jealousy
  is the Spirit he has caused to live in us? (Phillips)
  Or think ye that, in vain, the scripture speaketh? Is it, for envying,
  that the spirit which hath taken an abode within us doth crave?
  (Rotherdam)