It did. There were several wars between the two nations, and a brief Iberian Union at the end of the 16th century.
Here are a couple of previous threads on the subject of Iberian unity/Portuguese independence:
http://www.reddit.com/r/AskHistorians/comments/17hfbv/how_did_portugal_remain_independant_from_spain/
http://www.reddit.com/r/AskHistorians/comments/149fgx/to_what_extent_is_portugal_just_another_one_of/